package com.xinhua;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xinhua.domian.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class UserMapperTest3 {
    @Test
    public void testById() {
        User user = new User();
        user.setId(1);
        User user1 = user.selectById();
        System.out.println(user1);
    }


    @Test
    public void testinsert() {
        User user = new User();
        user.setUsername("liubei");
        user.setPassword("1234");
        user.setName("刘备");
        user.setEmail("liubei@test132");
        user.setAge(20);
        //调用AR的insert方法进行插入数据
        boolean insert = user.insert();
        System.out.println(insert);
    }

    @Test
    public void testupdateById() {
        User user = new User();
        user.setId(1);
        user.setAge(20);
        boolean b = user.updateById();
        System.out.println(b);
    }

    /*乐观锁测试*/
    @Test
    public void testupdateVersion() {
        User user = new User();
        user.setId(3);
        user.setAge(40);
        user.setVersion(1);//当前版本信息
        boolean b = user.updateById();
        System.out.println(b);
    }

    @Test public void testDeleteById(){
        User user = new User();
        user.deleteById(21);
    }


    @Test
    public void testdeleteById() {
        User user = new User();
        boolean a = user.deleteById(12);
        System.out.println(a);
    }

    @Test
    public void testselectList() {
        User user = new User();
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        queryWrapper.gt("age",20);//年龄大于20岁的查询出来
        List<User> users = user.selectList(queryWrapper);
        for (User u:users) {
            System.out.println(u);
        }
    }
}
